<?php

namespace IDock\Insurance\ZYIC\Request;

use IDock\Insurance\ZYIC\ZYICEnums;
use IDock\Insurance\ZYIC\Request\AllZYICRequest;
use IDock\Insurance\ZYIC\Response\VehicleActualValueResponse;
use IDock\Visitor\VehicleActualValueVisitor;

class VehicleActualValueRequest extends AllZYICRequest
{
    public $route = 'channelInterface/V09';

    protected $response = VehicleActualValueResponse::class;

    protected $urlTip = '车辆实际价值';

    /*** @var  VehicleActualValueVisitor $visitor */
    protected $visitor;

    public function generate(): array
    {
        $arr = [
            'riskCode' => $this->visitor->isNewEnergy  ? 'DEG' : 'DEB',
            'purchasePrice' => $this->visitor->vehiclePrice,
            'enrollDate' => date('Y-m-d',strtotime($this->visitor->firstRegisterDate)),
            'startDate' => date('Y-m-d',strtotime($this->visitor->startDate)),
            'carKind' => ZYICEnums::$carKindCode[$this->visitor->carKindCode] ?? '',
            'useNature' => ZYICEnums::$causeType[$this->visitor->causeType] ?? '',
            'seatCount' => intval($this->visitor->vehicleSeat),
            'rateCode' => ZYICEnums::$energyType[$this->visitor->energyType] ?? '',
        ];
        if(empty($arr['carKind'])){
            throw new \Exception("不支持该车辆类型");
        }
        if(empty($arr['useNature'])){
            throw new \Exception("不支持该车辆使用性质");
        }
        return $arr;
    }

}
